#ifndef IMAGE_DEVICE_HPP
#define IMAGE_DEVICE_HPP

#include <string>
#include <vector>
#include <fstream>
#include <stdexcept>
#include <boost/filesystem.hpp>
#include "Defines.hpp"
#include "Utils.hpp"

enum class DeviceState {
    NOT_PRESENT = 0x00,
    MEDIUM_CHANGE,
    READY,
    NOT_READY,
    BAD_MEDIA
};

constexpr int BLOCK_LENGTH = 2048;

class ImageDevice {
public:
    // 构造函数，接受镜像文件路径
    explicit ImageDevice();

    // 析构函数，关闭文件
    ~ImageDevice();

    void SetFilePath(MountType type, const std::string& filePath);

    void SetDeviceState(DeviceState state) { deviceState_ = state; }
    DeviceState GetDeviceState() const { return deviceState_; }
    size_t GetFileSize();

    // 读取指定偏移和长度的数据
    int ReadData(std::vector<uint8_t>& dataBuffer, size_t offset, size_t length);
    DeviceState TestUnitReady();

private:
    FileType fileType_; // 文件类型
    std::ifstream fileStream_; // 文件流
    std::string filePath_;     // 文件路径
    size_t fileSize_;          // 文件大小
    DeviceState deviceState_; // 媒体状态
};

#endif // IMAGE_DEVICE_HPP